-
Notifications
You must be signed in to change notification settings - Fork 288
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
TextKit 2 - Implement basic TK2 class and graceful fallback to TK1 #1690
TextKit 2 - Implement basic TK2 class and graceful fallback to TK1 #1690
Conversation
Generated by 🚫 Danger |
📲 You can test the changes from this Pull Request in Simplenote Prototype Build by scanning the QR code below to install the corresponding build.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@charliescheer I spotted a couple issues (while running on an iOS 18 device):
Bug: No Text + Crasher
- Add a new Note with a single line
- Go back to the Notes List
- Open the note again
As a result, the text is not visible. If you attempt to type anything, Simplenote crashes.
ScreenRecording_12-23-2024.12-28-02_1.MP4
Bug: No Style
- Add a new Note
- Write more than one line
As a result, the H1 style is never applied.
ScreenRecording_12-23-2024.12-29-07_1.MP4
So the problem with the crashing was how the fallback was being setup. It could mean that there was no text when changes were applied, so the ranges would always be out of bounds. Discussed in slack and decided instead to approach this in a feature branch rather than building a fallback. In theory if we are not using TK1 properties then we don't need to fallback. We don't use them too much already, so if we patch over those for iOS 17 and higher then we should be fine to stay in TK2 always. Updating the PR to reflect that |
As for the editing of the header in a new note, this PR is just setting up the TK2 properties and displaying existing notes, it doesn't yet handle editing. That will come later. |
textLayoutManager.textContainer = container | ||
|
||
} else { | ||
layoutManager.addTextContainer(container) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quick note: layoutManager
may not be init'ed by the time it's called here
// | ||
extension SPTextView: NSTextContentStorageDelegate { | ||
public func textContentStorage(_ textContentStorage: NSTextContentStorage, textParagraphWith range: NSRange) -> NSTextParagraph? { | ||
guard let originalText = textContentStorage.textStorage?.attributedSubstring(from: range) as? NSMutableAttributedString else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing .mutabelCopy()
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussed over Slack, the mutableCopy()
change is coming up in a follow up.
Please feel free to once the NSLayoutManager
initialization is fixed (fallback flow!).
Nice work @charliescheer !!!
Fix
This PR is the first step in implementing Textkit 2 into Simplenote. Why do we need this? Well primarily it is to keep up with the next paradigms in apple development. Also with the addition of Textkit 2 we should get all of the new Apple intelligence features for free. Lastly, by removing the reliance on glyphs and glyph ranges in TextKit 2, we should be able to fix many of the out of range crashes that we sometimes see with multi bit character languages.
Here I have taken the first steps. I have:
NOTE: this PR is broken for iOS 16 and older. That is fixed in #1691
Test
UITextView 0x10500fe00 is switching to TextKit 1 compatibility mode because its layoutManager was accessed
but the text is still styledNOTE: When the editor becomes first responder the text will lose formatting because it has fallen back to text kit 1.
Review
(Required) Add instructions for reviewers. For example:
Release
(Required) Add a concise statement to
RELEASE-NOTES.txt
if the changes should be included in release notes. Include details about updating the notes in this section. For example:These changes will require an update, but not yet